﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SLog
{
    public class Slog
    {
        private static Slog slogInstance = null;
        private static StreamWriter Log;
        private readonly string fileName = $@"TestLog_{DateTime.Now.Date.ToString("yyyyMMddHHmmss")}.md";
        private readonly string sPath = $@"./slog/";
		private Slog()
        {
			if (!Directory.Exists(sPath))
			{
				Directory.CreateDirectory(sPath);
			}

			Log = File.AppendText(Path.Combine(sPath,fileName));
		}

        /// <summary>
        /// 返回日志输出实例
        /// </summary>
        public static Slog SlogInstance
        {
            get
            {
                if (slogInstance == null)
                {
                    slogInstance = new Slog();
                }
                return slogInstance;
            }
        }

        /// <summary>
        /// 像日志中输出
        /// </summary>
        /// <param name="infomation">要输出的信息</param>
        public void WriteLine(string infomation = "")
        {
            Log.WriteLine(infomation);
        }

        /// <summary>
        /// 关闭日志记录
        /// </summary>
        public static void Close()
        {
            Log.Close();
            slogInstance = null;
        }
    }
}
